package com.blog.cloud.auth.router;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

@Configuration(proxyBeanMethods = false)
public class AuthRouter {

    /*
    * 创建一个路由器，将请求路径为/hello的请求交给GreetingHandler处理
    * 除了这样定义路由器之外，webflux 也支持像Spring MVC那样的注解路由，具体可以参考官方文档 https://docs.spring.io/spring-framework/reference/web/webflux.html
    * https://docs.spring.io/spring-framework/reference/
    * */
    @Bean
    public RouterFunction<ServerResponse> route(GreetingHandler greetingHandler) {
        return RouterFunctions
                .route(GET("/hello").and(accept(MediaType.APPLICATION_JSON)), greetingHandler::hello);
    }
}
